<template>
  <n-dropdown
    :trigger="trigger"
    :options="options"
    class="biu-dropdown"
    size="small"
    :style="style"
    placement="bottom-start"
    :theme-overrides="dropdownThemeOverrides"
  >
    <slot></slot>
  </n-dropdown>
</template>

<script lang="ts" setup>
import { type DropdownProps } from "naive-ui"
import { useThemeStore } from "@/stores/theme"
import { computed, ref } from "vue"
import VariableName from "@/stores/theme/variable-name"

defineProps({
  trigger: {
    type: String,
    required: false,
    default: "click"
  },
  options: {
    type: Array,
    required: true
  },
  width: {
    type: Number,
    require: false,
    default: 200
  }
})

const themeStore = useThemeStore()

const style = ref({
  "--dropdown-background": themeStore.getThemeType(
    "rgba(50, 50, 50, 0.55)",
    "rgba(255, 255, 255, 0.6)"
  ),
  "--dropdown-arrow-background": themeStore.getThemeType(
    "rgba(50, 50, 50, 0.3)",
    "rgba(255, 255, 255, 0.6)"
  )
})

type DropdownThemeOverrides = NonNullable<DropdownProps["themeOverrides"]>

const dropdownThemeOverrides = computed<DropdownThemeOverrides>(() => {
  return {
    optionColorHover: themeStore.getVariable(VariableName.Theme.primaryColor),
    optionTextColorHover: "#fff",
    borderRadius: "7px",
    fontSizeSmall: "13px",
    optionHeightSmall: "25px",
  }
})
</script>

<style scoped lang="scss"></style>

<style lang="scss">
.biu-dropdown {
  background: var(--dropdown-background);
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
  backdrop-filter: blur(11px);
  -webkit-backdrop-filter: blur(11px);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-weight: normal;

  .n-dropdown-divider {
    margin: 7px var(--n-option-prefix-width);
  }
}
</style>
